package com.itheima.Controller;

import com.itheima.common.entity.Result;
import com.itheima.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 套餐接口
 */
@RestController
@RequestMapping("/setmeal")
@Slf4j
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 获取套餐列表
     *
     * @return
     */
    @PostMapping("/getSetmeal")
    public Result getSetmeal() {
        log.info("获取套餐列表");
        try {
            return new Result(true, "查询成功", setmealService.getSetmeal());
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "查询失败");
        }
    }

    /**
     * 根据套餐id查询套餐详情
     *
     * @param id
     * @return
     */
    @PostMapping("/findById")
    public Result findById(Integer id) {
        log.info("根据id查询套餐：{}", id);
        try {
            return new Result(true, "查询成功", setmealService.findById(id));
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "查询失败");
        }
    }
}
